// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "RubikActor.generated.h"

UCLASS()
class RUBIKCUBE_API ARubikActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ARubikActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere, Category = "RubikCube")
	TSubclassOf<AActor> cube_BP;

	UPROPERTY(EditAnywhere, Category = "RubikCube")
	int dimension;

	UPROPERTY(EditAnywhere, Category = "RubikCube")
	float cubeExtent;

	UFUNCTION(BlueprintCallable, Category = "RubikCube")
	void BeginRotateCube(AActor *cubeActor, FVector hitLocation);

	UFUNCTION(BlueprintCallable, Category = "RubikCube")
	void EndRotateCube();

private:
	TArray<TArray<TArray<AActor*>>> _cubeMatrix;
	FVector _hitLocation;
	FVector _cameraLocation;
	FVector _cameraDirection;
	TObjectPtr<AActor> _cubeActor;
	TObjectPtr<APlayerController> _playerController;
	bool _isRotating;
	FVector2D _movementInput;
	FVector2D _cameraInput;

	void createRubik();
	FVector getMouseOnTouchPlane();

	void pitchCube(float axisValue);
	void yawCube(float axisValue);
};
